lambda calculus
λ-calculus
#logic #PLT
#logic #PLT
Overview
Three elements, variables, functions, and applications
- variable,
<name>, e.g.x - function,
λ<parameters>.<body>, e.g.λx.x - application,
<function><variable or function>, e.g.(λx.x)a, calling functionλx.xwith argumenta
Free vs bound variables
xis bound variable inλx.xas it is in both body of function and a parameter- (example here
λx.xis the identity function, equivalent to )
- (example here
yis a free variable inλx.yas it is not declared beforehand
Evaluation
- using β-reduction, i.e. lexically-scoped substitution
- can extend lambda calculus to create multi-parameter functions using currying
- e.g.
(λx.λy.λz.xyz)
- e.g.
- notation,
λxy.<body>sometimes written instead ofλx.λy.<body>
Church encoding
Boolean logic
Tasλx.λy.xFasλx.λy.y- true and false as choosing for first or second of two values respectively (Church booleans)
Numbers
- using Church numerals to encode numbers, as a unary encoding
n = λf.fⁿ0 = λf.λx.x1 = λf.λx.f x2 = λf.λx.f(f x)
- successor function ,
S = λn.λf.λx.f((n f) x)
Arithmetic
- can use successor function e.g.
ADD = λab.(a S)b
Notes
- formal system to express computation using function abstraction
- lambda calculus can be used to represent any Turing machine despite lack of numbers, strings, booleans, non-function datatypes
- it is Turing complete (see Church-Turing thesis)